﻿<UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  
             x:Class="IndexMarkSilverlightClient.Views.Controls.VolumsPPS"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:my="clr-namespace:IndexMarkSilverlightClient.Views.Controls"                                  
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"  
    xmlns:prim="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"                           
    xmlns:classes="clr-namespace:IndexMarkSilverlightClient.Classes" xmlns:inputToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" xmlns:Controls="clr-namespace:SharedCode.Controls;assembly=SharedCode" xmlns:Interop="clr-namespace:System.Windows.Interop;assembly=System.Windows" xmlns:System="clr-namespace:System;assembly=mscorlib" mc:Ignorable="d"
    d:DesignHeight="400" d:DesignWidth="600"
    Loaded="UserControl_Loaded">

    <UserControl.Resources>
    <classes:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
        <Style TargetType="prim:DataGridColumnHeader" x:Name="PPSListStyle">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <ItemsControl BorderThickness="0" BorderBrush="Transparent" Background="Transparent" ItemsSource="{TemplateBinding Content}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <controlsToolkit:WrapPanel/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Border BorderBrush="Gray" BorderThickness="0, 0, 1, 0" Padding="0">
                                        <TextBlock HorizontalAlignment="Center" Text="{Binding Person}" FontWeight="Bold" Width="215" Margin="3"/>
                                    </Border>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>



        <ControlTemplate x:Key="VolumePPSToolTipTemplate">
            <Border CornerRadius="4" BorderBrush="#FF2754DD" BorderThickness="2" Background="#DDBADADA">
                <Grid Margin="3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <Ellipse Fill="#FF7098EE" Height="32" Width="32"/>
                    <Ellipse Stroke="White" StrokeThickness="4" Fill="White" Height="30" Width="30"/>
                    <TextBlock Text="i" FontSize="24" FontWeight="Bold" VerticalAlignment="Center" FontFamily="Georgia" HorizontalAlignment="Center" Foreground="#FF7098EE"/>

                    <ContentPresenter Grid.Column="1"
                                      Content="{TemplateBinding Content}"
                                      ContentTemplate="{TemplateBinding ContentTemplate}" 
                                      Margin="{TemplateBinding Padding}" 
                                      VerticalAlignment="Center"/>
                </Grid>
            </Border>
        </ControlTemplate>

        <classes:NullableFloatToHideConverter x:Key="NullableFloatToHideConverter"/>

        <Style TargetType="Button" x:Name="ButtonStyle">
            <Setter Property="Width" Value="24"/>
            <Setter Property="Height" Value="24"/>
            <Setter Property="Margin" Value="5,0,0,0"/>
        </Style>

    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition />
        </Grid.RowDefinitions>

        <Border BorderBrush="Gray" BorderThickness="0, 0, 0, 2">
            <StackPanel Orientation="Horizontal" Grid.Row="0">
                <Button ToolTipService.ToolTip="Настройки" Style="{StaticResource ButtonStyle}" Click="Button_Click_2">
                    <Image Source="../../Resources/Tools.png" />
                </Button>
                
                <Button ToolTipService.ToolTip="Экспорт в Excel" Style="{StaticResource ButtonStyle}" Click="Button_Click">
                    <Image Source="../../Resources/microsoftofficeexcel.png"/>
                </Button>

            </StackPanel>
        </Border>

        
        
        
        <data:DataGrid x:Name="VolumsGrid" IsReadOnly="True" Grid.ColumnSpan="3" ItemsSource="{Binding}" 
                       Grid.Row="1" AutoGenerateColumns="False" LoadingRowGroup="VolumsGrid_LoadingRowGroup" SelectionMode="Single">


            <data:DataGrid.Columns>
                
                <data:DataGridTemplateColumn CanUserResize="False">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="{Binding Category.ImagePath}" Margin="3, 0, 3, 0" ToolTipService.ToolTip="{Binding Category.Name}"/>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>
                
                <data:DataGridTemplateColumn Header="Показатель" Width="150">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding Char}" Margin="3, 0, 3, 0"/>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>


                
                
                
                <!--<data:DataGridTemplateColumn Header="Максимум">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <HyperlinkButton Content="{Binding Max}" Click="HyperlinkButton_Click"  HorizontalAlignment="Center" Foreground="CadetBlue" Margin="3, 0, 3, 0"/>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>-->

                <data:DataGridTextColumn Header="Ед. изм." Binding="{Binding Unit}"/>

                <data:DataGridTemplateColumn HeaderStyle="{StaticResource PPSListStyle}">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ItemsControl x:Name="ChildTable" BorderThickness="0" BorderBrush="Transparent" Background="Transparent" ItemsSource="{Binding Volums}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <controlsToolkit:WrapPanel/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border BorderBrush="Gray" BorderThickness="0, 0, 1, 0" Padding="0">
                                            <StackPanel Orientation="Vertical">
                                            <!--
                                                <TextBlock Text="{Binding Volume, Converter={StaticResource NullableFloatToHideConverter}}" Width="100" Margin="3">
                                                <ToolTipService.ToolTip>
                                                    <ToolTip Template="{StaticResource VolumePPSToolTipTemplate}">
                                                        <ToolTip.Content>
                                                            <Grid>
                                                                <Grid.RowDefinitions>
                                                                    <RowDefinition/>
                                                                    <RowDefinition/>
                                                                </Grid.RowDefinitions>

                                                                <TextBlock Text="Объем * вес градации (если есть) * вес показателя * вес категории * вес раздела" Margin="3" Grid.Row="0"/>
                                                                <TextBlock Text="{Binding VolumeWithWeight}" Margin="3" Grid.Row="1" FontWeight="Bold"/>
                                                            </Grid>
                                                        </ToolTip.Content>
                                                    </ToolTip>
                                                </ToolTipService.ToolTip>
                                                </TextBlock>

                                                -->
                                                <!--<ListBox ItemsSource="{Binding Gradations}" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ItemContainerStyle="{StaticResource NotSelectedListBoxItemStyle}" Background="Transparent" BorderBrush="Transparent" BorderThickness="0">
                                                    <ListBox.ItemTemplate>
                                                        <DataTemplate>
                                                            <StackPanel Orientation="Horizontal">
                                                                <TextBlock Text="{Binding Volume}" TextWrapping="Wrap"/>
                                                            </StackPanel>
                                                        </DataTemplate>
                                                    </ListBox.ItemTemplate>
                                                </ListBox>-->

                                                <StackPanel Orientation="Horizontal" Width="221">
                                                    <classes:xDataGrid x:Name="ChildTable" ItemsSource="{Binding Answers}" 
                                                           AutoGenerateColumns="False" BorderBrush="Red"  BorderThickness="0,0,0,0"
                                                            SelectionMode="Single" SelectedItem="{x:Null}"
                                                           HeadersVisibility="None" Loaded="ChildTable_Loaded">
                                                        <classes:xDataGrid.Columns>

                                                            <data:DataGridTemplateColumn Header="Градация" IsReadOnly="True" Width="175" >
                                                                <data:DataGridTemplateColumn.CellTemplate>
                                                                    <DataTemplate>

                                                                        <ItemsControl ItemsSource="{Binding Gradations}" ScrollViewer.HorizontalScrollBarVisibility="Hidden"  Background="Transparent"  BorderBrush="Gray" BorderThickness="0,0,0,0">
                                                                            <ItemsControl.ItemTemplate>
                                                                                <DataTemplate>
                                                                                    
                                                                                    <StackPanel Orientation="Horizontal" ScrollViewer.HorizontalScrollBarVisibility="Hidden" >
                                                                                        
                                                                                        <TextBlock Text="{Binding}" TextWrapping="Wrap" ToolTipService.ToolTip="{Binding}" Width="175" />
                                                                                        
                                                                                        <StackPanel Orientation="Horizontal" Visibility="{Binding Volume, Converter={StaticResource NullToVisibilityConverter}}" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
                                                                                            <TextBlock Text=" - " />
                                                                                            <TextBlock Text="{Binding Volume}" Margin="3, 0, 0, 0" />
                                                                                        </StackPanel>
                                                                                   
                                                                                 </StackPanel>
                                                                                </DataTemplate>
                                                                            </ItemsControl.ItemTemplate>
                                                                        </ItemsControl>

                                                                    </DataTemplate>
                                                                </data:DataGridTemplateColumn.CellTemplate>
                                                            </data:DataGridTemplateColumn>

                                                            <!--<data:DataGridTemplateColumn Header="Значение" Width="20">
                                                                <data:DataGridTemplateColumn.CellTemplate>
                                                                    <DataTemplate>
                                                                        <TextBlock Loaded="TextBlock_Loaded" HorizontalAlignment="Left" Margin="5, 0, 0, 0" VerticalAlignment="Center" FontWeight="Bold"/>
                                                                    </DataTemplate>
                                                                </data:DataGridTemplateColumn.CellTemplate>
                                                            </data:DataGridTemplateColumn>-->
                                                            
                                                            <data:DataGridTemplateColumn Header="Значение" Width="45" >
                                                                <data:DataGridTemplateColumn.CellTemplate >
                                                                    <DataTemplate>
                                                                        
                                                                        <Border BorderThickness="0,0,1,0">
                                                                            <StackPanel>
                                                                                <ToolTipService.ToolTip>
                                                                            <ToolTip Template="{StaticResource VolumePPSToolTipTemplate}">
                                                                                <ToolTip.Content>
                                                                                    <Grid>
                                                                                        <Grid.RowDefinitions>
                                                                                            <RowDefinition/>
                                                                                            <RowDefinition/>
                                                                                        </Grid.RowDefinitions>

                                                                                        <TextBlock Text="Объем * вес градации (если есть) * вес показателя * вес категории * вес раздела" Margin="3" Grid.Row="0"/>
                                                                                        <TextBlock Text="{Binding VolumeWithWeight}" Margin="3" Grid.Row="1" FontWeight="Bold"/>
                                                                                    </Grid>
                                                                                </ToolTip.Content>
                                                                            </ToolTip>
                                                                        </ToolTipService.ToolTip>
                                                                           
                                                                        <TextBlock Text="{Binding Volume}" HorizontalAlignment="Left" Margin="5, 0, 0, 0" VerticalAlignment="Center" FontWeight="Bold"/>                             
                                                                        </StackPanel>
                                                                        </Border>
                                                                    </DataTemplate>
                                                                </data:DataGridTemplateColumn.CellTemplate>
                                                            </data:DataGridTemplateColumn>
                                                        </classes:xDataGrid.Columns>
                                                    </classes:xDataGrid>

                                                    <!--<ListBox BorderThickness="0" BorderBrush="Transparent" ItemsSource="{Binding Answers}" Width="30" >
                                                        <ListBox.ItemTemplate>
                                                            <DataTemplate>
                                                                <TextBlock Text="{Binding Volume}" FontWeight="Bold" />
                                                            </DataTemplate>
                                                        </ListBox.ItemTemplate>
                                                    </ListBox>-->

                                                </StackPanel>

                                            </StackPanel>
                                        </Border>
                                    </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                              
                                       

                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>

            </data:DataGrid.Columns>
        </data:DataGrid>    

        <Controls:LoadingBar Grid.RowSpan="3" VerticalAlignment="Center" HorizontalAlignment="Center" Action="загрузка" x:Name="loadingBar" Grid.ColumnSpan="3"/>

    </Grid>
</UserControl>
